package com.example.applicationview.view;

import android.content.Context;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;

import com.example.applicationview.R;

/**
 * 三角-矩形 view
 */
public class TriangleRectView extends BaseView {
    public TriangleRectView(Context context) {
        super(context);
        init();
    }

    public TriangleRectView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init(){
        setLayerType( LAYER_TYPE_SOFTWARE , null);
//        mPaint.setColor(Color.GREEN);
        mPaint.setTextSize(25);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //只显示外部的发光区域
//        mPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.OUTER));

        Rect rect = new Rect(100 , 100 , mWidth - 100, mHeight-100);
        canvas.drawRect(rect, mPaint);

        mPaint.setColor(getResources().getColor(R.color.black));
        //画4个顶点
        canvas.drawPoint(100, 100, mPaint);
        canvas.drawPoint(100, mHeight-100, mPaint);
        canvas.drawPoint(mWidth - 100, 100, mPaint);
        canvas.drawPoint(mWidth - 100, mHeight-100, mPaint);

//        Path path = new Path(); //Paint.Style.FILL的时候，path需要是闭合路径才可以
//        path.lineTo(mWidth - 100, mHeight-100);
//        path.lineTo(mWidth - 100, 100);
//        path.close();
//        canvas.drawPath(path, mPaint);

        //画3角path
        Path path = new Path(); //Paint.Style.FILL的时候，path需要是闭合路径才可以
        path.moveTo(100, 100);
        path.lineTo(200, 0);
        path.lineTo(300, 100);
        path.close();
        canvas.drawPath(path, mPaint);

//        canvas.drawLine(100, 100,100, mHeight-100, mPaint);
    }
}